package com.bms.client.controller;

import com.bms.client.pojo.LunWen;
import com.bms.client.service.impl.LunWenServiceImpl;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 论文管理与检索表(LunWen)表控制层
 *
 * @author godmaker
 * @since 2021-03-16 15:49:17
 * @version 1.0
 */
@RestController
@RequestMapping("guanLiLunWen")
@Api(value = "论文管理与检索表(LunWen)管理",tags = "论文管理与检索表(LunWen)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class LunWenController {

    /**
     * 服务对象
     */
    @Resource
    private LunWenServiceImpl lunWenServiceImpl;


//    //定时任务：
//    @Autowired
//    ScheduleSave scheduleSave;




    /**
     * 通过主键查询单条数据
     * @param page  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "chaXunFenYe", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "mingCheng",value = "**名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> chaXunFenYe(@RequestParam(name = "page") int page) {

        return this.lunWenServiceImpl.chaXunFenYe(page);
    }

    /**
     * 通过主键查询单条数据
     * @param page  需要查询的页码
     * @param page, tiMu, zuoZhe,faBiaoWeiZhi,lunWenLeiBie,faBiaoShiJianQiShi,faBiaoShiJianJieShu  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "chaXunFenYe01", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "mingCheng",value = "**名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> chaXunFenYe01(@RequestParam(name = "page") int page, String tiMu,String zuoZhe,
                                             String faBiaoWeiZhi,String lunWenLeiBie,
                                             String faBiaoShiJianQiShi,String faBiaoShiJianJieShu) {
        return this.lunWenServiceImpl.chaXunFenYe01(page, tiMu, zuoZhe,faBiaoWeiZhi,lunWenLeiBie,
                                                        faBiaoShiJianQiShi,faBiaoShiJianJieShu);
    }
    
    /**
     * 查询所有已发表的论文数据
     * @return 返回所有已发表的论文数据
     */
//    @Scheduled
    @RequestMapping(value = "chaXunAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有已发表的论文数据接口",notes = "查询所有已发表的论文数据接口",httpMethod = "GET")
    public Map<String, Object> chaXunAll() {
        return this.lunWenServiceImpl.chaXunAll();

    }


    @RequestMapping(value = "chaXunById", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询某篇已发表的论文存储地址的数据接口",notes = "根据id查询某篇已发表的论文存储地址的数据接口",httpMethod = "GET")
    public Map<String, Object> chaXunById(int id) {
        return this.lunWenServiceImpl.chaXunById(id);

    }

    @RequestMapping(value = "xiaZai", method = RequestMethod.POST)
    @ApiOperation(value = "通过存储地址下载当前论文的数据接口",notes = "下载当前论文的数据接口",httpMethod = "POST")
    public Map<String, Object> xiZai(HttpServletRequest request, HttpServletResponse response, String diZhi) {
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","下载成功");
        map.put("list",this.lunWenServiceImpl.xiaZai(request,response,diZhi));
        return map;
    }




    /**
     * 查询所有已发表的论文数据
     * @return 返回所有已发表的论文数据
     */
    @RequestMapping(value = "chaXunCaoGao", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有未发表的论文数据接口",notes = "查询所有未发表的论文数据接口",httpMethod = "GET")
    public Map<String, Object> chaXunCaoGao(int page) {

        return this.lunWenServiceImpl.chaXunCaoGao(page);
    }



    /**
     * 通过论文类别查询相关数据
     * @return 返回该类别论文相关数据
     */
    @RequestMapping(value = "chaXunByLeiBie", method = RequestMethod.GET)
    @ApiOperation(value = "通过论文类别查询相关数据接口",notes = "通过论文类别查询相关数数据接口",httpMethod = "GET")
    public Map<String, Object> chaXunByLeiBie(@RequestParam(name = "lunWenLeiBie")String lunWenLeiBie) {
        return this.lunWenServiceImpl.chaXunByLeiBie(lunWenLeiBie);
    }







    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "shanChuById", method = RequestMethod.GET)
    @ApiOperation(value = "根据一个主键删除一条**记录的接口",notes = "根据一个主键删除一条**记录的接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> shanChuById(@RequestParam("id") String id) {
        return this.lunWenServiceImpl.shanChuById(id);
    }
    
//    /**
//     * 通过主键更新单条数据
//     *
//     * @param lunWen 一个数据库对应的POJO数据对象
//     * @return 单条数据
//     */
//    @RequestMapping(value = "gengXinById", method = RequestMethod.POST)
//    @ApiOperation(value = "通过主键更新一个**的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
//    public Map<String, Object> gengXinById(
////            @RequestBody @ApiParam(name = "lunWen",value = "pojo模型",required = false)
////            @RequestBody @ApiParam(name = "request",value = "pojo模型",required = false)
////            @RequestBody @ApiParam(name = "file",value = "pojo模型",required = false)
//                                                       LunWen lunWen, HttpServletRequest request,
//                                                       @RequestParam(required =true)
//                                                               MultipartFile file) {
//        return this.lunWenServiceImpl.gengXinById(lunWen,request,file);
//    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param lunWen 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZeng", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个**的接口",notes = "根据完整记录新增一个**的接口",httpMethod = "POST")
    public Map<String, Object> xinZeng(
//            @RequestBody @ApiParam(name = "lunWen",value = "pojo模型",required = true)//不能以json格式上传文件
                                                   LunWen lunWen,
                                                   HttpServletRequest request,
                                                   MultipartFile file) {
        System.out.println(lunWen);
        return this.lunWenServiceImpl.xinZeng(lunWen,request,file);
    }


//    @RequestMapping(value = "/chaXun", method = RequestMethod.GET)
//    @ApiOperation(value = "模糊查询数据列表接口", notes = "返回所有的数据列表",
//            httpMethod = "GET", response = String.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page",value = "第几页",   //根据分页查询返回指定页面的角色信息
//                    required = false,dataType = "int",paramType = "query"),
//            @ApiImplicitParam(name = "guanJianZi",value = "关键字",
//                    required = false,dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "chaXunTiaoJian",value = "查询条件",
//                    required = false,dataType = "String",paramType = "query"),
//            //以上只能单个条件模糊查询
//    })
//    public Map<String,Object> chaXun(
//            @RequestParam(value = "page", required = true) int page,
//            @RequestParam(value = "guanJianZi", required = false) String guanJianZi,
//            @RequestParam(value = "chaXunTiaoJian", required = false) String chaXunTiaoJian
//    ){
//        return this.lunWenServiceImpl.chaXun(page, guanJianZi, chaXunTiaoJian);
//    }






 //以下是多条件联合查询
   //查询日志管理表的所有记录
    @RequestMapping(value = "/lianHeChaXun", method = RequestMethod.GET)
    @ApiOperation(value = "联合，模糊查询数据列表接口", notes = "返回所有的数据列表",
            httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page", value = "页码",
//                    required = false, dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "chaXunTiaoJian", value = "查询条件",
//                    required = false, dataType = "String", paramType = "query"),
//            @ApiImplicitParam(name = "id", value = "",
//            @ApiImplicitParam(name = "jiGouMingCheng", value = "机构名称",
//                    required = false, dataType = "String", paramType = "query")

//            @ApiImplicitParam(name = "",value = "请输入论文id",
//                    required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "tiMu",value = "请输论文题目",
                    required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "zuoZhe",value = "请输入论文作者",
                    required = false,dataType = "String",paramType = "query"),
//              @ApiImplicitParam(name = "zhuangTai",value = "请输入论文状态",
//                    required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "faBiaoWeiZhi",value = "请输入论文发表位置",
                    required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "lunWenLeiBie",value = "请输入论文类别",
                    required = false,dataType = "String",paramType = "query"),
              @ApiImplicitParam(name = "faBiaoShiJianQiShi",value = "请输入论文发表的起始时间",
                    required = false,dataType = "Date",paramType = "query"),
              @ApiImplicitParam(name = "faBiaoShiJianJieShu",value = "请输入论文发表的结束时间",
                    required = false,dataType = "Date",paramType = "query"),

                })
    public Map<String,Object> lianHeChaXun(
//            @RequestParam(value = "page", required = true) int page,
//            @RequestParam(value = "guanJianZi", required = false) String guanJianZi,
//            @RequestParam(value = "chaXunTiaoJian", required = false) String chaXunTiaoJian
                                     @RequestParam(value = "page", required = false) int page,
                                     @RequestParam(value = "tiMu", required = false) String tiMu,
                                     @RequestParam(value = "zuoZhe", required = false) String zuoZhe,
                                     @RequestParam(value = "faBiaoWeiZhi", required = false) String faBiaoWeiZhi,
                                     @RequestParam(value = "lunWenLeiBie", required = false) String lunWenLeiBie,
                                     @RequestParam(value = "faBiaoShiJianQiShi", required = false) String faBiaoShiJianQiShi,
                                     @RequestParam(value = "faBiaoShiJianJieShu", required = false) String faBiaoShiJianJieShu
    ){
        return this.lunWenServiceImpl.lianHeChaXun(page, tiMu, zuoZhe,faBiaoWeiZhi,lunWenLeiBie,
                faBiaoShiJianQiShi,faBiaoShiJianJieShu);
    }
}

